package DB;

import java.util.Vector;

public class IndependetProjection extends Projection{

/*
 * Constructor
 */
	
	public IndependetProjection(RAQuery raq,Vector<String> fields) {
		super(raq, fields);
	}
	

/*
 * @see DB.Projection#calcProb(int, DB.Table, java.util.Vector)
 * IndependedProjection calculates the probability by the schema   
 *  1 - (1 - p1)*(1 - p2)*(1 - p3)*....
 *  p1, p2, p3 ... is the probabilities of the matching tuples.
 */
	protected double calcProb(int index, Table t,Vector<String> currTuple) {
		double ans = 1 - t.getTupleProp(index);
		for (int i = index + 1 ; i < t.getSize(); i++ ){
			if (compareTuples(t, currTuple, t.getTuple(i))){
				ans = ans * (1 - t.getTupleProp(i));
			}
		}
		return 1 - ans;
	}

}
